// pages/home/index.js
import moment from "moment";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    mz: "",
    sc: "",
    show: false,
    show2:false,
    fieldValue: '',
    cascaderValue: '',
    minHour: 10,
    maxHour: 20,
    minDate: new Date(new Date().getFullYear() - 100, 1, 1).getTime(),
    maxDate: new Date(2019, 10, 1).getTime(),
    currentDate: new Date().getTime(),
    sex: false,
    region: [],// 选中的数据
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  showPopup() {
    this.setData({ show: true });
  },
  onClick() {
    this.setData({
      show2: true,
    });
  },
  onClose() {
    this.setData({ show: false });
  },
  onInput(event) {
    //event.detail转成年月时日分

    this.setData({
      currentDate: event.detail,
      sc: moment(event.detail).format("YYYY-MM-DD HH:mm"),
    });

    console.log(":", this.data.sc);
  },
  onChange({ detail }) {
    console.log("onChange", detail);
    this.setData({ sex: detail });
  },
//点击确定按钮
bindRegionChange: function (e) {
  console.log(e.detail.value)
  console.log(e.detail.code)
  this.setData({
    region: e.detail.value
  })
},

  tj() {
    const now = moment(this.data.currentDate);
    const year = now.year(); // 获取当前年份
    const month = now.month() + 1; // 获取当前月份，注意月份是从0开始的
    const day = now.date(); // 获取当前日期
    const hour = now.hour(); // 获取当前小时（24小时制）
    const minute = now.minute(); // 获取当前分钟
    let userinfo = {
      name: this.data.mz,
      sex: this.data.sex ? 0:1,
      year,
      month,
      day,
      hour,
      minute,
      p:this.data.region[0],
      c:this.data.region[1],
      a:this.data.region[2],
    };

    
    console.log('userinfo:',userinfo)
    // userinfo 存入 stroge
    wx.setStorage({
      key: "userinfo",
      data: userinfo,
    });
    wx.navigateTo({
      url: '../main/index',
    });

  },
});
